package com.test.mooan.labama.activity_fragment_boom.fragment_boom;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.test.mooan.labama.R;
import com.test.mooan.labama.activity_fragment_boom.base_boom.BaseApplication_boom;
import com.test.mooan.labama.activity_fragment_boom.base_boom.BaseLnFragment_boom;
import com.test.mooan.labama.bean_boom.config_info_boom.AppShowInfo_boom;
import com.test.mooan.labama.bean_boom.user_info_boom.LnLimitInfo_boom;
import com.test.mooan.labama.dialog_boom.CustomerServiceDialog_boom;
import com.test.mooan.labama.utils_boom.Permissionutil_boom;
import com.test.mooan.labama.utils_boom.analytics_boom.util_boom.AnalyticsUtil_boom;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;
import com.test.mooan.labama.utils_boom.http_boom.HttpManager_boom;

import pub.devrel.easypermissions.EasyPermissions;


public class LnMainFragment_boom extends BaseLnFragment_boom {

    private TextView loanAmountTv;

    public boolean isRefresh = false;

    private TextView limit1Tv, limit2Tv;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pageTag = "HOME";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_ln_main_boom, container, false);
        init_boom(view);
        return view;
    }

    @SuppressLint("SetTextI18n")
    private void init_boom(View view) {

        loanAmountTv = view.findViewById(R.id.fragment_loan_main_tv_loan_amount);
        limit1Tv = view.findViewById(R.id.fragment_loan_main_tv_limit_1);
        limit2Tv = view.findViewById(R.id.fragment_loan_main_tv_limit_2);

        view.findViewById(R.id.fragment_loan_main_ib_customer_service).setOnClickListener(v -> {
            new CustomerServiceDialog_boom(requireContext()).show();
        });

        SwipeRefreshLayout refreshLayout = view.findViewById(R.id.fragment_ln_main_refreshlayout);
        refreshLayout.setOnRefreshListener(() -> {
            isRefresh = true;
            HttpManager_boom.getInstance().requestUserProcess();
            refreshLayout.setRefreshing(false);
        });

        View.OnClickListener applybtncl = v -> {

            UserInfoHelper_boom.gInstance().addEventPoint((pageTag + "_APPLY_CLICK").toUpperCase());

            HttpManager_boom.getInstance().saveUserPointForBatch();

            isRefresh = false;
            HttpManager_boom.getInstance().requestUserProcess();

        };

        view.findViewById(R.id.fragment_loan_main_btn_apply).setOnClickListener(applybtncl);
        view.findViewById(R.id.fragment_loan_main_btn_apply_2).setOnClickListener(applybtncl);

        HttpManager_boom.getInstance().queryLoanLimit();

    }

    @SuppressLint("SetTextI18n")
    public void updateLoanAmount_boom() {
        isRefresh = false;
        String cuurrency = LnLimitInfo_boom.getInstance().gCurrency();
        loanAmountTv.setText(cuurrency + " " + LnLimitInfo_boom.getInstance().gLimitAmount());
        limit1Tv.setText(cuurrency + " " + LnLimitInfo_boom.getInstance().gLimitIncreasedAmount1());
        limit2Tv.setText(cuurrency + " " + LnLimitInfo_boom.getInstance().gLimitIncreasedAmount2());

        HttpManager_boom.getInstance().fetchDropConfig();

    }

}